Why am I getting a Cannot access offset of type string on string error in my PHP code